package logic

import (
	"context"
	"rpc/pb/cart"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type StatusLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusLogic {
	return &StatusLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *StatusLogic) Status(req *types.CartStatusRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	userid := 1
	status, err := l.svcCtx.CartRpc.CartStatus(l.ctx, &cart.CartStatusRequest{
		UserId:  int64(userid),
		GoodsId: req.GoodsId,
		Checked: req.Checked,
	})
	if err != nil {
		return &types.Response{
			Code: "500",
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}

	return &types.Response{
		Code: "200",
		Msg:  "商品选中状态更新成功",
		Data: map[string]interface{}{
			"status": status,
		},
	}, nil
}
